﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title>宾果高校</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/sweetalert.min.css" />
    <script src="../js/jquery-1.12.2.min.js"></script>
    <script src="../js/validator.min.js"></script>
    <script src="../js/common.js"></script>
    <script src="../js/angular.min.js"></script>
    <script src="../js/Controller.js"></script>
    <script src="../js/sweetalert.min.js"></script>
</head>
<body id="bodyContent">
    <div id="searchPage"></div>
    <div class="main">
        <div class="wrap">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="form-wrap">
                        <form id="formValidate" action="" class="form-horizontal">
                            <!--<div class="form-group">
                                <label for="">高校名称</label>
                                <input type="text" placeholder="高校名称" readonly class="form-control">
                            </div>-->
                            <div class="form-group">
                                <label for="">社团名称</label>
                                <select id="AssociationNO" data-error="请选择社团" required min="1" class="form-control">
                                    <option value="" selected="selected">请选择社团</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="">社团口令</label>
                                <input type="text" id="SelfPassword" placeholder="此口令来自所选择的社团在被创建后，平台颁发的口令" data-error="此口令来自所选择的社团在被创建后，平台颁发的口令" required class="form-control">
                                <div class="help-block with-errors"></div>
                            </div>
                            <div class="form-group text-center">
                                <button type="button" class="btn btn-default" onclick="Go()">绑定</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script>

    $("#searchPage").load("header.html", function () {
        SetCss("Assoc");
    });

    //后台需要注意的是当提交了绑定按钮后，平台需要直接判断所输入的口令是否是其选择的社团口令。如果不是的话，那么就要弹框显示口令错误。
    common.commonAjax({ type: 'Get', url: '../api/student/GetAllAssoc', sMethod: AfteAjax });

    function AfteAjax(ctx) {

        if (ctx == "" || ctx == null) {
            window.location = "../login.html";
            return;
        }

        var data = ctx.ResponseDict;
        if (data == null) {
            common.alertMessage("贵校无任何社团可以加入");
            return;
        }
      
        for (var a in data)
            $("#AssociationNO").append("<option value='" + a + "'>" + data[a] + "</option>")

    }

    function AfteAjax1(ctx) {

        if (ctx == "" || ctx == null) {
            window.location = "../login.html";
            return;
        }

        window.location = "view.html";
    }

    function Go() {

        if (!common.validateForm())
            return;

        var values = common.GetCtrlValues({
            ContentID: "formValidate"
        })

        common.commonAjax({ type: 'Post', url: '../api/student/BindAssoc', data: values, sMethod: AfteAjax1, alert: true, loadingCtrl: $("#bodyContent") });
    }

</script>